import pymysql
def query_to_test(last_id, is_next):
    conn = pymysql.connect(host='192.168.31.16', port=3306, user='root', passwd='root', db='tianyin_newsall',charset='utf8')
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
    if is_next:  # 上一页
        cursor.execute('select * from commom_imei where id>%s limit 10', last_id)
        ret = cursor.fetchall()
    else:  # 下一页
        cursor.execute('select * from commom_imei where id<%s order by id desc limit 10', last_id)
        ret = cursor.fetchall()
        ret = list(reversed(ret))
    conn.commit()
    cursor.close()
    conn.close()
    return ret

current_first_id = 0
current_last_id = 0
while True:
    p = input('1.上一页 | 2.下一页 >>>')
    if p == '2':
        is_next = True
        ret = query_to_test(current_last_id, is_next)
    else:
        is_next = False
        ret = query_to_test(current_first_id, is_next)
        current_last_id = current_last_id + 1

    current_first_id = ret[0]['id']  # 结果集开始id
    current_last_id = ret[-1]['id']  # 结果集结束id
    #print(ret)
    for i in ret:
        print(i)